import { program, Command } from "commander";
import { IProcess } from "./IProcess";
import { Version } from "../Version";
import { ArkLeakProc } from "./ArkLeakProc";
import { ArkGCProc } from "./ArkGCProc";
import { ArkCompareProc } from "./ArkCompareProc";
import { ArkStatProc } from "./ArkStatProc";

/**
 * MemInsight Process
 */
export class MemInsight implements IProcess {
    public readonly CMD : string = "meminsight";
    public readonly DESC : string = "meminsight binary is a command tool for memory analysis.";
    public readonly VER : string;
    
    public constructor(ver: string, processes: IProcess[]) {
        this.VER = ver;
        this.initialize(new Command(), processes);
    }

    public initialize(proc: Command, any?: any) : void{
        program.name(this.CMD);
        program.description(this.DESC);
        program.version(this.VER, "-v, --version", "meminsight version");
        let processes = any as IProcess[];
        if (processes) {
            processes.forEach(process => process.initialize(program));
        }
    }

    /**
     * work
     */
    public work() : void{ 
        program.parse();
    }
}

export const meminsight: MemInsight = new MemInsight(
    Version.HMEMX.toString(),
    [ 
        ArkStatProc.instance(),
        ArkCompareProc.instance(),
        ArkLeakProc.instance(),
        ArkGCProc.instance(),
    ]
);